<!DOCTYPE html>
<html lang="en">
<head>
    <meta charset="UTF-8">
    <meta http-equiv="X-UA-Compatible" content="IE=edge">
    <meta name="viewport" content="width=device-width, initial-scale=1.0">
    <title>Document</title>
   <style>
       div {
           position: absolute;
           left: 0;
           width: 200px;
           height: 200px;
           background-color: pink;
       }
   </style>
</head>
<body>
    <div></div>
    <script>
        var div = document.querySelector('div');
        //obj是移动的对象，target是移动的目标距离
        function animate(obj,target){
            obj.timer = setInterval(function(){
            if(obj.offsetLeft>=target){
                clearInterval(obj.timer);
            }
            obj.style.left = obj.offsetLeft + 1 +'px';
        },30);
        }
        animate(div,300);
    </script>
</body>
</html>